package models

import (
	"errors"
	"github.com/astaxie/beego/orm"
	"github.com/astaxie/beego/validation"
	"log"
	//"time"
)

type admin struct {
	Id         int64
	AdminName  string `orm:"uinque;size(60)" form:"adminName" valid:"Required;MinSize(4);MaxSize(20)"`
	Password   string `orm:"type(text)" form:"password"`
	Phone      string `orm:"size(11)" form:"phone" valid:"Required;MinSize(11);MaxSize(11)"`
	Email      string `orm:"size(50)" form:"email" valid:"Required;MinSize(8);MaxSize(50)"`
	CreateTime int64  `orm:"size(10)" valid:"Required"`
}

//自定义模型(表名)
func (a *admin) TableName() string {
	return "yii2_admin"
}

//检查管理员信息
func checkAdmin(a *admin) (err error) {
	valid := validation.Validation{}
	b, _ := valid.Valid(&a)

	if !b {
		for _, err := range valid.Errors {
			log.Println(err.Key, err.Message)
			return errors.New(err.Message)
		}
	}
	return nil
}

//初始化
func init() {
	orm.RegisterModel(new(admin))
}
